package copyengine.utils
{

	/**
	 * @author Steven
	 */
	public final class UUIDFactory
	{
		private static var singleton:UUIDFactory;

		private var factor:Number;

		/**
		 * 唯一的前缀
		 */
		private var prefix:String;

		public static function get instance():UUIDFactory
		{
			if (!singleton)
			{
				singleton=new UUIDFactory(new Singleton());
			}

			return singleton;
		}

		public function setUniquePR(_pr:String):void
		{
			prefix=_pr;
			//每次设置PR时候清空factor,让其从0开始计数
			factor=new Number();
		}

		public function UUIDFactory(lock:Singleton)
		{
			factor=new Number();
			//在获得系统时间之前使用10个随机字符初始化前缀
			//这个时间需要UUID的地方是Mediator
			prefix=Random.bit(10);
		}

		public function generateUUID():String
		{
			return prefix + factor++;
		}
	}
}

internal class Singleton
{

}
